<template>
  <div>
    <el-form ref=""  label-width="80">
      <el-form-item label="我的昵称" style="display: flex">
        <el-input v-model="info.name"></el-input>
      </el-form-item>
      <el-form-item label="我的性别" style="display: flex">
        <el-radio v-model="radio"  label="1">男</el-radio>
        <el-radio v-model="radio"  label="0">女</el-radio>
      </el-form-item>
      <el-form-item label="我的身高" style="display: flex">
        <el-input v-model="info.tall"></el-input>
      </el-form-item>
      <el-form-item label="我的体重" style="display: flex">
        <el-input v-model="info.weight"></el-input>
      </el-form-item>
      <el-form-item label="我的目标" style="display: flex">
        <el-radio v-model="myaim" label="1">减脂</el-radio>
        <el-radio v-model="myaim" label="2">塑型</el-radio>
        <el-radio v-model="myaim" label="3">增肌</el-radio>
        <button @click="btn" style="margin-left: 300px;width: 60px">保存</button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
    export default {
      name:"Changeinfo",
      inject:['reload'],
      data () {
        return {
          info:{
            name:this.$store.state.user_info[0].name,
            tall:this.$store.state.user_info[0].tall,
            weight:this.$store.state.user_info[0].weight,
          },
          radio:null,
          myaim:null,
        };
      },
      created(){
        this.info=this.$store.state.user_info[0]
        // console.log(this.info);
        if(this.info.sex==1){
          this.radio='1'
        }else{
          this.radio='0'
        }


        if(this.info.aim==1){
          this.myaim="1"
        }
        else if(this.info.aim==2){
          this.myaim="2"
        }
        else{
          this.myaim="3"
        }

        // console.log(this.info.radio);
      },

      methods:{

        btn:function () {
          var this_=this;
          var telephone=this.$store.state.telephone
          this_.$store.state.user_info[0].name=this_.info.name;
          // this_.$store.state.radio=this_.info.radio;
          // this_.radio=this_.info.radio;
          this_.$store.state.tall=this_.info.tall;
          this_.$store.state.weight=this_.info.weight;
          // this_.$store.state.myaim=this_.info.myaim;
          // this_.myaim=this_.info.myaim;


          this.$axios.post('http://127.0.0.1:8080/record/update_user', {
            "name":  this_.$store.state.user_info[0].name,
            "sex": this_.radio,
            "aim":  this_.myaim,
            "weight":  this_.$store.state.weight,
            "tall":  this_.$store.state.tall,
            "tel":  this_.$store.state.telephone,
          })
            .then(function (response) {
              // alert(response.data)
              if(response.data===1){
                this_.$router.push("/blank")
              }
            })
            .catch(function (error) {
              console.log(error);
            });
        }
      },
    }
</script>

<style scoped>

</style>
